﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BarTender;
using Microsoft.SqlServer.Server;

namespace TSCPrintUnit
{
    public class TSCPrint
    {

        private static BarTender.Application btApp = new BarTender.Application();
        private static BarTender.Format btFormat = new BarTender.Format();

        Dictionary<string, string> dict = new Dictionary<string, string> { };

        public void AddDict(string key, string value)
        {
            dict[key] = value;
        }
        public TSCPrint()
        {

        }
        /// <summary>
        /// 打印标签
        /// </summary>
        /// <param name="printerName">打印机名称</param>
        /// <param name="btFileName">文件模板路径</param>
        /// <param name="CopiesOfLabel">打印份数</param>
        public void Print(string printerName, string btFileName, int CopiesOfLabel)
        {
            btFormat = btApp.Formats.Open(btFileName);
            btFormat.PrintSetup.Printer = printerName;
            btFormat.IdenticalCopiesOfLabel = CopiesOfLabel;
            foreach (var item in dict)
            {
                btFormat.SetNamedSubStringValue(item.Key, item.Value);
            }
            btFormat.PrintOut(false, false);
            //不保存标签退出
            btFormat.Close(BarTender.BtSaveOptions.btDoNotSaveChanges);
        }
    }
}
